package net.towee.model.repo.impl;

import java.util.Date;

import net.towee.model.repo.DocumentNode;
import net.towee.model.repo.NodeData;
import net.towee.model.repo.TreeNode;
import net.towee.server.persistence.impl.MongoDbStore;

import com.google.code.morphia.annotations.Entity;
import com.google.code.morphia.annotations.Id;

/**
 * Node of the repository tree implementation
 * @author c58
 */
@Entity(MongoDbStore.NODES_COLLECTION)
public class NodeDataImpl implements NodeData, TreeNode {
	@Id protected String id;
	protected Date creationDate;
	protected String parentId;
	protected String groupId;
	protected String path;
	protected boolean trash;
	private String name;
	
	public NodeDataImpl() {}
	public NodeDataImpl(String id) {
		this.id = id;
	}
	public NodeDataImpl(String id, String groupId, String name) {
		this.id = id;
		this.creationDate = new Date();
		this.groupId = groupId;
		this.trash = false;
		this.path = "/";
		this.name = name;
		this.parentId = null;
	}
	
	@Override
	public String getId() {
		return id;
	}

	@Override
	public String getGroupId() {
		return groupId;
	}
	
	@Override
	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}

	@Override
	public String getParentId() {
		return parentId;
	}
	
	@Override
	public void setParentId(String id) {
		this.parentId = id;		
	}

	@Override
	public String getPath() {
		return path;
	}

	@Override
	public void setPath(String path) {
		this.path = path;
	}

	@Override
	public Date getCreationDate() {
		return creationDate;
	}
	
	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}
	@Override
	public String getPathForChildren() {
		return path+name+"/";
	}
	
	@Override
	public boolean equals(Object o) {
		if(o == this)
			return true;
		if(o instanceof NodeData && ((NodeData)o).getId().equals(getId()))
			return true;
		
		return false;
	}
	
	@Override
	public DocumentNode toDocumentNode() {
		return null;
	}
	@Override
	public TreeNode toTreeNode() {
		return this;
	}
	@Override
	public void setId(String string) {
		this.id = string;
	}
	@Override
	public void setCreationDate(Date date) {
		this.creationDate = date;
	}
}
